package com;

import java.util.ArrayList;
import java.util.Hashtable;

/**
 * Created with IntelliJ IDEA.
 * User: Lenovo
 * Date: 24.11.2012
 * Time: 15:01
 * To change this template use File | Settings | File Templates.
 */
public class SymbolTable implements ISymbolTable
{
   // private Hashtable<SymbolTableEntry, Integer> symTable = new Hashtable<SymbolTableEntry, Integer>();
    private ArrayList<String> symbolTable = new ArrayList<String>();
    // To iterate thew arrayList , you can use indexOf which is integer, if the element is not in the list the function will be equal
    // to (-1) if the element is NOT in the list

    @Override
    public SymbolTableEntry Insert(String lexeme)
    {
        int i = symbolTable.indexOf(lexeme);

        if(i == -1)
        {
            symbolTable.add(lexeme);
            return new SymbolTableEntry(lexeme);
        }
        else
        {
            return null;
        }
    }

    @Override
    public SymbolTableEntry LookUp(String lexeme)
    {
        int i = symbolTable.indexOf(lexeme);

        if(i == -1)
        {
              return null;    // fann ekki i listanum
        }
        else
        {
            return new SymbolTableEntry(lexeme);
        }
    }

}
